package com.designPattern.foctory.absFactory.show;

import com.designPattern.foctory.absFactory.factory.factoryBuilder.InstanceFactoryBuilder;
import com.designPattern.foctory.absFactory.instance.Instance;
import com.designPattern.foctory.absFactory.factory.factoryImpl.BadInstanceFactory;
import com.designPattern.foctory.absFactory.factory.factoryImpl.GoodInstanceFactory;
import com.designPattern.foctory.absFactory.instance.BadInstance;
import com.designPattern.foctory.absFactory.instance.GreatInstance;
import com.designPattern.foctory.absFactory.instance.WroseInstance;

/**
 * 【快速使用指南】
 * 【基本原理介绍】
 * 【工厂模式】
 * 【抽象工厂模式】
 * 创建一个抽象的工厂接口，让子类去创建实例的具体方法
 * 创建一个创建工厂的对象AbsInstanceFactoryBuilder，通过传入具体工厂实现类
 * 在AbsInstanceFactoryBuilder中通过调用factory的createInstance()方法去创建具体实例
 * @author mxs
 */
public class QuickUse {
    public static void main(String[] args) {
        //将InstanceFactory对象作为参数传入InstanceFactoryBuilder
        InstanceFactoryBuilder instanceFactoryBuilder = new InstanceFactoryBuilder(new BadInstanceFactory());
        //根据参数创建对应实例
        Instance instance = instanceFactoryBuilder.getInstance(BadInstance.class.getName());
        //调用相应的方法
        instance.method1();
        instance.method2();

        Instance instance1 = instanceFactoryBuilder.getInstance(WroseInstance.class.getName());
        instance1.method1();
        instance1.method2();

        //【详细使用】
        //创建InstanceFactory
        GoodInstanceFactory goodInstanceFactory = new GoodInstanceFactory();
        //通过InstanceFactory创建InstanceFactoryBuilder
        InstanceFactoryBuilder instanceFactoryBuilder1 = new InstanceFactoryBuilder(goodInstanceFactory);
        //设置InstanceType(实例的类型)
        String instanceType = GreatInstance.class.getName();
        //根据InstanceType创建实例
        Instance instance2 = instanceFactoryBuilder1.getInstance(instanceType);
        //调用实例中的方法
        instance2.method1();


    }
}
